package cn.com.bluemoon.daps.api.sync;

import cn.com.bluemoon.daps.api.sync.factory.RemoteSyncServiceFallbackFactory;
import cn.com.bluemoon.daps.common.annotation.FcApiFor;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSync;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.sync.base.ApplyPassGroup;
import cn.com.bluemoon.daps.sync.base.ApplyRevertGroup;
import cn.com.bluemoon.daps.sync.vo.applypublish.ApplyPublishParam;
import cn.com.bluemoon.daps.sync.vo.applypublish.ApplyPublishResultVo;
import cn.com.bluemoon.daps.sync.vo.applypublish.ModelCompareVo;
import cn.com.bluemoon.daps.sync.vo.applypublish.TableApplyPublishReportVo;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 同步服务接口
 *
 * @author Jarod.Kong
 */
@FeignClient(value = DapsApiSync.SERVICE, fallbackFactory = RemoteSyncServiceFallbackFactory.class)
@RequestMapping(DapsApiSync.BASE_URI + DapsApiSync.API_SYNC)
@ApiIgnore
@FcApiFor
public interface RemoteSyncService {

    /**
     * 申请发布-模型版本对比前-决策-最新模型表是否与语法问题-不为空则有语法问题
     *
     * @param modelId 模型id
     * @return 为空则语法正常，不为空则存在语法问题
     */
    @PostMapping("/application/compareV/predicate")
    public ResultBean<List<TableApplyPublishReportVo>> modelTableLayerPredicate(@RequestParam(value = "modelId") @ApiParam(value = "模型id") String modelId);

    /**
     * 模型申请发布-模型版本对比（最新版（new）vs最新已发布版（old）
     *
     * @param modelId  模型id
     * @param newVsOld true 为最新版（new）对比 最新已发布版（old），false 为最新已发布版（old）对比 最新版（new）， 默认为true
     * @return ResultBean
     */
    @PostMapping("/application/compareV")
    public ResultBean<List<ModelCompareVo>> compareModelVersion(@RequestParam(value = "modelId") @ApiParam(value = "模型id") String modelId,
                                                                @RequestParam(value = "newVsOld", required = false, defaultValue = "true")
                                                                @ApiParam(value = "true 为最新版（new）对比 最新已发布版（old），false 为最新已发布版（old）对比 最新版（new）， 默认为true") Boolean newVsOld,
                                                                @RequestParam(value = "forceOverride", required = false, defaultValue = "false")
                                                                @ApiParam(value = "是否强制拉取对比且覆盖上一次对比结果，true是 false否，默认为false") Boolean forceOverride);


    /**
     * 申请发布-模型版本对比V2-语法检查报告（最新版（new）vs最新已发布版（old）
     *
     * @param modelId  模型id
     * @param newVsOld true 为最新版（new）对比 最新已发布版（old），false 为最新已发布版（old）对比 最新版（new）， 默认为true
     * @return ResultBean
     */
    @PostMapping("/application/compareV2")
    @Deprecated
    public ResultBean<ApplyPublishResultVo> compareModelVersionV2(@RequestParam(value = "modelId") @ApiParam(value = "模型id") String modelId,
                                                                  @RequestParam(value = "newVsOld", required = false, defaultValue = "true")
                                                                  @ApiParam(value = "true 为最新版（new）对比 最新已发布版（old），false 为最新已发布版（old）对比 最新版（new）， 默认为true") Boolean newVsOld,
                                                                  @RequestParam(value = "forceOverride", required = false, defaultValue = "false")
                                                                  @ApiParam(value = "是否强制拉取对比且覆盖上一次对比结果，true是 false否，默认为false") Boolean forceOverride);

    /**
     * 申请发布-确认通过
     *
     * @param applyPublishParam 申请发布-通过
     * @return ResultBean
     */
    @PostMapping("/application/pass")
    ResultBean<String> applyConfirmPass(@Validated(value = {ApplyPassGroup.class}) @RequestBody ApplyPublishParam applyPublishParam);

    @PostMapping("/application/unpass")
    ResultBean<String> applyConfirmUnPass(@Validated(value = {ApplyPassGroup.class}) @RequestBody ApplyPublishParam applyPublishParam);

    /**
     * 申请发布-撤销
     *
     * @param applyPublishParam 申请发布-通过
     * @return ResultBean
     */
    @PostMapping("/application/revert")
    ResultBean<String> applyRevert(@Validated(value = {ApplyRevertGroup.class}) @RequestBody ApplyPublishParam applyPublishParam);

}
